package 力扣._1_两数之和;

import java.util.*;

class Solution3 {
    public int[] twoSum(int[] nums, int target) {
        // 哈希改进，不可重复，则遍历时候必会遇到目标值在map中的情况
        Map<Integer,Integer> map = new HashMap<>();
        for (int i = 0; i < nums.length; i++) {
            if(map.containsKey(target-nums[i]))
                return new int[]{i, map.get(target-nums[i])};
            map.put(nums[i],i);
        }
        return null;
        
    }

    public static void main(String[] args) {
        Solution3 solution3 = new Solution3();
        int[] ints = solution3.twoSum(new int[]{3, 2, 4}, 6);
        System.out.println(Arrays.toString(ints));
    }
}